package com.fantasy.demo1.config;

import com.fantasy.demo1.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * 注册多个过滤器，通过FilterRegistrationBean的setOrder方法可以决定Filter的执行顺序
 */
@Configuration
public class MyFilterConfig {

    @Resource
    MyFilter myFilter;

    @Bean
    public FilterRegistrationBean<MyFilter> thirdFilter() {
        FilterRegistrationBean<MyFilter> filterFilterRegistrationBean = new FilterRegistrationBean<>();

        filterFilterRegistrationBean.setFilter(myFilter);

        filterFilterRegistrationBean.setUrlPatterns(new ArrayList<>(Arrays.asList("/api/*")));

        return filterFilterRegistrationBean;

    }
}
